#include "mconfig.h"
#include "def.h"
#include <QDebug>
#include <QCoreApplication>
#include <QFile>

MConfig::MConfig(QObject *parent) :
    QObject(parent)
{

}

void MConfig::clear(){
    this->cfgfile="";
    this->methods_path="";
}

bool MConfig::load(const QString &fname){
    this->clear();
    this->cfgfile=fname;
    //test exist cfg file, if not exist to create default config
    if(!QFile::exists(this->cfgfile)){
        // create default
        this->methods_path=QString(QCoreApplication::applicationDirPath()).append("/methods");
        return true;
    }else{
        // open
        this->inconf = new QSettings(this->cfgfile,QSettings::IniFormat);
        if(cfgver != this->inconf->value("main/version").toString()){
            return false;
        }
        this->methods_path=this->inconf->value("main/methods_path").toString();
        if(this->methods_path==""){
            this->methods_path=QString(QCoreApplication::applicationDirPath()).append("/methods");
        }
        return true;
    }
}

bool MConfig::save(){

    return true;
}
